#!//opt/bin/lv_micropython -i
import usys as sys
sys.path.append('')
sys.path.append('./driver')

import utime as time
import lvgl as lv

# from uasyncio import sleep, create_task, Loop, CancelledError
# import lv_utils

lv.init()

# init display driver
# Register FB display driver
import fb
fb.init()

#event_loop = lv_utils.event_loop(freq = 60, asynchronous=True)

# Register  FB display driver
LCD_W = 720
LCD_H = 1280
disp_buf1 = lv.disp_draw_buf_t()
buf1_1 = bytes(LCD_W*LCD_H//10)
#buf1_2 = bytes(LCD_W*10)
disp_buf1.init(buf1_1, None, len(buf1_1)//4)
disp_drv = lv.disp_drv_t()
disp_drv.init()
disp_drv.draw_buf = disp_buf1
disp_drv.flush_cb = fb.flush
disp_drv.hor_res = LCD_W
disp_drv.ver_res = LCD_H
disp_drv.register()


# Create a screen
scr = lv.obj()
scr.clear_flag(scr.FLAG.SCROLLABLE) #关闭滚动效果
#scr.set_style_bg_color(lv.color_hex3(0x011), lv.PART.MAIN)

print("scr.get_width():",scr.get_width())
print("scr.get_height():",scr.get_height())
# Load the screen
lv.scr_load(scr)

# select the py example file
#from example import calendar
#from example import keyboard
#from example import gif_show
#from example import jpg_show
#from example import png_show
#from example import simple_tabview
#from example import left_tabview
#from example import flex
#from example import meter
from example import clock


# Regiser mouse and touchscreen device and crosshair cursor
import evdev
mouse = evdev.mouse_indev(scr)
tp = evdev.tp_indev(scr,device='/dev/input/event2')

#Loop.run_forever()
# if __name__ == '__main__':
    # while True:
        # time.sleep(1)
        # #lv.scr_load(scr)
        # pass